"""
应用配置
创建时间：2025-09-12
作者：开发团队
目的：定义应用核心配置参数
"""

import os



class Config:
    """应用基础配置"""
    
    # 项目名称
    PROJECT_NAME: str = "新易访内网系统"
    
    # 版本信息
    VERSION: str = "1.0.0"
    
    # API前缀
    API_V1_STR: str = "/api/v1"
    
    # 密钥配置
    SECRET_KEY: str = os.getenv("SECRET_KEY", "your-secret-key-change-in-production")
    
    # 数据库配置
    DATABASE_URL: str = os.getenv("DATABASE_URL", "sqlite:///./qev.db")
    
    # JWT配置
    JWT_ALGORITHM: str = "HS256"
    JWT_ACCESS_TOKEN_EXPIRE_MINUTES: int = 60 * 24 * 8  # 8天
    
    # 加密配置
    AES_KEY_LENGTH: int = 32  # AES-256
    
    # 分页配置
    DEFAULT_PAGE_SIZE: int = 20
    MAX_PAGE_SIZE: int = 100
    
    # 文件上传配置
    MAX_UPLOAD_SIZE: int = 10 * 1024 * 1024  # 10MB
    ALLOWED_EXTENSIONS: set[str] = {".jpg", ".jpeg", ".png", ".pdf", ".xlsx"}
    
    # 日志配置
    LOG_LEVEL: str = os.getenv("LOG_LEVEL", "INFO")
    LOG_FILE: str = os.getenv("LOG_FILE", "app.log")


class DevelopmentConfig(Config):
    """开发环境配置"""
    
    DEBUG: bool = True
    DATABASE_URL: str = os.getenv("DEV_DATABASE_URL", "sqlite:///./qev_dev.db")


class ProductionConfig(Config):
    """生产环境配置"""
    
    DEBUG: bool = False
    DATABASE_URL: str = os.getenv("DATABASE_URL", "sqlite:///./qev.db")


class TestingConfig(Config):
    """测试环境配置"""
    
    TESTING: bool = True
    DATABASE_URL: str = "sqlite:///./test.db"


# 配置映射
config_map = {
    "development": DevelopmentConfig,
    "production": ProductionConfig,
    "testing": TestingConfig
}

# 获取当前配置
def get_config() -> Config:
    """
    获取当前环境配置
    :return: 配置对象
    """
    env = os.getenv("ENVIRONMENT", "development")
    return config_map.get(env, DevelopmentConfig)()